/* 2017/05/07 */
package org.sample.springboot.converter.uppercase;

import java.lang.reflect.Field;

import org.sample.springboot.converter.SingleFieldConverter;
import org.sample.springboot.util.ReflectUtils;

public class UpperCaseConverter extends SingleFieldConverter {

	@Override
	protected boolean isScanTargetField(Field field) {
		if (!String.class.isAssignableFrom(field.getType())) {
			return false;
		}
		
		UpperCase[] annotations = field.getAnnotationsByType(UpperCase.class);
		return annotations.length > 0;
	}

	@Override
	protected boolean isConvertTargetField(Field field) {
		if (!String.class.isAssignableFrom(field.getType())) {
			return false;
		}
		return true;
	}

	@Override
	protected void convertTargetField(Field field, Object object, Object value) {
		if (value != null) {
			String str = (String) value;
			ReflectUtils.setValue(object, field, (String) str.toUpperCase());
		}
	}

}
